package tt.dz.egobus.servicemanager.facade.user;

import com.alibaba.dubbo.config.annotation.Reference;
import tt.dz.egobus.api.ResponseBack;
import tt.dz.egobus.api.exception.ResponseException;
import tt.dz.egobus.api.usercenter.user.UserApiService;
import tt.dz.egobus.api.usercenter.user.UserBack;
import tt.dz.egobus.api.usercenter.user.UserInfoApiService;
import tt.dz.egobus.api.usercenter.user.UserInfoBack;
import tt.dz.egobus.bean.ServiceManagerI18NCodeEnum;
import tt.dz.egobus.servicemanager.facade.interator.Facade;

/**
 * @author Anson
 * @date 17-3-20
 * @name
 * @since 1.0.1
 */
@Facade(facadeName = "usercenter")
public class UserCenterFacade {

    @Reference(version = "1.0.1",timeout = 10000)
    private UserApiService userApiService;

    @Reference(version = "1.0.1",timeout = 10000)
    private UserInfoApiService userInfoApiService;


    /**
     * @param driverId 司机id
     * @author Anson
     * @date 17-3-23
     * @name 验证并校验司机
     * @since 1.0.2
     */
    public UserInfoBack validateAndGetUserInfo(String driverId) {
        ResponseBack<UserInfoBack> userInfoBackResponseBack = this.findUserInfo(driverId);
        if (!userInfoBackResponseBack.isSuccess() || userInfoBackResponseBack.getResult() == null) {
            throw new ResponseException(ServiceManagerI18NCodeEnum.RPC_USER_NOT_FOND);
        }
        return userInfoBackResponseBack.getResult();
    }


    public ResponseBack<UserBack> registerMember(String username, String password) {
        return userApiService.registerMember(username, password);
    }

    public ResponseBack<UserBack> loginMember(String username, String password, String ip,int businessCode) {
        return userApiService.loginMember(username, password, ip,businessCode);
    }

    public ResponseBack<UserBack> activateDriver(String username, String realName, String idcard) {
        return userApiService.activateDriver(username, realName, idcard);
    }


    public ResponseBack<UserBack> forgetPassword(String userId, String password,int businessCode) {
        return userApiService.forgetPassword(userId, password,businessCode);
    }

    public ResponseBack<UserInfoBack> findUserInfo(String uid) {
        return userInfoApiService.findUserInfo(uid);
    }

    public ResponseBack<UserBack> submitUserInfo(UserInfoBack back) {
        return userInfoApiService.submitUserInfo(back);
    }
}
